<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>慕课网办公OA系统</title>
    <!--引入layui的css-->
    <link rel="stylesheet" href="/resources/layui/css/layui.css">
<style type="text/css">
    body
    {
        background-color: white;
    }
    .oa-container{
        background-color: white;
    position: absolute;
    width: 400px;
    height: 350px;
    top:50%;
    left:50%;
    padding: 20px;
        margin-left: -200px;
        margin-top: -175px;
}
    #username,#password{
        text-align: center;
        font-size: 24px;
    }
</style>
</head>
<body>
<div class="oa-container">
    <h1 style="text-align: center;margin-bottom: 20px">慕课网办公OA系统</h1>
    <form class="layui-form">
        <div class="layui-form-item">
<!--            autocomplete属性设置是否开启自动提示输入历史-->
            <input type="text" id="username" class="layui-input" lay-verify="required" name="username" placeholder="请输入用户名" autocomplete="off"/>
        </div>
        <div class="layui-form-item">
            <input type="password" id="password" class="layui-input" lay-verify="required" name="password" placeholder="请输入密码" autocomplete="off"/>
        </div>
        <div class="layui-form-item">
            <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="login">登录</button>
        </div>

    </form>

</div>
<script src="/resources/layui/layui.all.js"></script>
<script type="text/javascript">
//()里的login是获得一个指定lay-filter值的提交按钮
    layui.form.on("submit(login)",function(formdata){
        //formdata参数包含了当前表单的数据
        console.log(formdata);
        //layui内置了jquery
        layui.$.ajax(
            {
                url:"/check_login",
                data:formdata.field,<!--表单的所有数据作为参数-->
                type:"post",
                dataType:"json",
                success:function (json)
                {
                    console.log(json);
                    if(json.code=="0")
                    {
                        // layui.layer.msg("登录成功");//弹出一个短暂存在的黑色的小提示框
                        window.location.href=json.redirect_url;
                    }
                    else{
                        layui.layer.msg(json.message);//弹出一个短暂存在的黑色的小提示框
                    }
                }
            }
        )
        return false;//submit提交事件返回true则表单提交，false则阻止表单提交
    })

</script>
</body>
</html>